﻿/*
=======================================================
    RegulatorData【数据权限】
=======================================================
*/

namespace Services
{
    public interface IRegulatorDataMapping : IMapping<RegulatorData, RegulatorDataModel, RegulatorDataFilterModel>
    { }

    public class RegulatorDataMapping : AutoRegulatorDataMapping, IRegulatorDataMapping
    {
        public RegulatorDataMapping(ICurrentUser currentUser)
            : base(currentUser)
        { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override RegulatorDataModel Entity2Model(RegulatorData entity)
        {
            if (entity == null)
            {
                return null;
            }

            RegulatorDataModel model = base.Entity2Model(entity);


            /***************************************** 下面处理自定义转换 *****************************************/

            model.Province_Name = entity.Province_Name;
            model.City_Name = entity.City_Name;
            model.Area_Name = entity.Area_Name;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override RegulatorData Model2Entity(RegulatorDataModel model)
        {
            RegulatorData entity = base.Model2Entity(model);


            /***************************************** 下面处理自定义转换 *****************************************/



            return entity;
        }
        #endregion

        #region 读数据(集合)
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entities">Entity对象</param>
        /// <returns></returns>
        public override List<RegulatorDataModel> Entity2Model(IEnumerable<RegulatorData> entities)
        {
            return entities.Select(x => Entity2Model(x)).ToList();
        }
        #endregion

        #region 写数据(集合)
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="models">ViewModel对象</param>
        /// <returns></returns>
        public override List<RegulatorData> Model2Entity(IEnumerable<RegulatorDataModel> models)
        {
            return models.Select(x => Model2Entity(x)).ToList();
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<RegulatorData> FilterModel2Where(RegulatorDataFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //SearchInput
            if (!string.IsNullOrEmpty(filterModel._SearchInput))
            { }


            return where;
        }
        #endregion
    }
}
